﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Nate_sRoguelikeGameXNA
{
    class PressedKeys :  IEquatable<Keys[]>
    {
        public GameTime GameTime { get; set; }
        public Keys[] Keys { get; set; }
        public PressedKeys(Keys[] keys, GameTime gameTime)
        {
            Keys = keys;
            GameTime = gameTime;
        }

        #region Implementation of IEquatable<Keys[]>

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(Keys[] other)
        {
            return other.Length == Keys.Length && !other.Except(Keys).Any();
        }

        /// <summary>
        /// Limits the keystroke repeats to once every 250 ms.
        /// </summary>
        /// <param name="currentGameTime"></param>
        /// <returns></returns>
        public bool IsRepeatAllowed(GameTime currentGameTime)
        {
            if ((currentGameTime.TotalGameTime - GameTime.TotalGameTime).TotalMilliseconds < 250)
            {
                GameTime = currentGameTime;
                return true;
            }
            return false;
        }
        #endregion
    }
}
